package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description OrderMapper
 * @Author 小平
 * @Date 2024-02-27 14
 */
@Mapper
public interface OrderMapper {
    /**
     * 订单分页查询
     * @param dto
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO dto);


    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);



    /**
     * 再来一单(获取原订单信息)
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders findByOrderId(Long id);

    /**
     * 根据订单id查询订单明细
     * @param orderId
     * @return
     */
    @Select("select * from order_detail where order_id = #{orderId}")
    List<OrderDetail> getByOrderId(Long orderId);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Select("select * from orders where user_id=#{userId}")
    Orders getByUserId(Long userId);
}
